package com.weiawei.ui;

import javax.swing.*;
import java.awt.event.MouseEvent;

public class ChooseLevel extends Menu {
    public static void main(String[] args) {
        new ChooseLevel();
    }

    public static final int EasyField = 1;

    public static final int middleField = 2;

    public static final int highestField = 3;

    /**
     * 初始化ChooseLevel
     * <p>
     * 作为Menu子类，直接调用父类的初始化方法，重写paintBackground就好
     */
    public ChooseLevel() {
        super();
    }


    /**
     * 绘制菜单的背景图片
     * 与窗口等大，面板透明
     */
    @Override
    public void paintBackground() {
        ImageIcon menuImage = new ImageIcon(this.getClass().getResource("/images/levelchoose.png"));
        JLabel menuLabel = new JLabel(menuImage);
        // 添加背景 并设置为窗口大小
        menuLabel.setBounds(0,0,this.getWidth(),this.getHeight());
        // 将背景置为容器最高层
        this.getLayeredPane().add(menuLabel , new Integer(Integer.MIN_VALUE));
        // 设置面板容器透明
        JPanel menuPanel = (JPanel) this.getContentPane();
        menuPanel.setOpaque(false);
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        int x = e.getX();
        int y = e.getY();
        if (x >= 70 && x <= 300) {
            if (y >= 215 && y <= 270) {
                //    初级难度
                dispose();
                new PVEMainBoard(EasyField);
            } else if (y >= 327 && y <= 383) {
                //    中级难度
               dispose();
                new PVEMainBoard(middleField);
            } else if (y >= 439 && y <= 485) {
                //    高级难度
                dispose();
               new PVEMainBoard(highestField);
            } else if (y >= 551 && y <= 597) {
                //    返回
                dispose();
                new InitialMenu();
            }
        }
    }
}
